package com.codeczx.myretrofitdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.codeczx.myretrofitdemo.retrofit.Call;
import com.codeczx.myretrofitdemo.retrofit.Retrofit;

import java.io.IOException;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        testMyRetrofit();
//        testOkHttp();
    }

    private void testOkHttp() {

        new Thread(new Runnable() {
            @Override
            public void run() {
                OkHttpClient client = new OkHttpClient();


                Request request = new Request.Builder()
                        .url("https://api.github.com/users/codeczx/repos")
                        .build();

                Response response = null;
                try {
                    response = client.newCall(request).execute();
                    Log.i(TAG, "run: " + response.body().string());
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }).start();


    }

    private void testMyRetrofit() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Retrofit retrofit = new Retrofit.Builder()
                        .baseUrl("https://api.github.com/")
                        .build();
                GithubService githubService = retrofit.create(GithubService.class);
                Call<ResponseBody> call = githubService.getRepos("codeczx");
                Log.i(TAG, "testMyRetrofit: " + call.execute().body().toString());
            }
        }).start();
    }
}
